<template>
  <div class="_wz_cent_main _wz_abnormalTraffic">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>
        <FormItem label="运输企业">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem label="车牌号">
          <i-input v-model="formDataSearch.vehiclePlateNo" placeholder="请填写车牌号" clearable />
        </FormItem>
        <FormItem label="行驶日期" v-if="searchType">
          <DatePicker dataformatas="yyyy-MM-dd" type="date" v-model="formDataSearch.createDate" @on-change='formDataSearch.createDate = $event' placeholder="请选择起运时间"></DatePicker>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <p slot="extra">
        <Button type="success" @click="vehicleExport">导出</Button>
      </p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>
  </div>
</template>

<script>
import wzTbale from "../../../components/table/table";

export default {
  components: {
    wzTbale,//列表
  },
  data() {
    return {
      subDeptList:[],
      searchType:false,
      formDataSearch: {},//搜索表单数据
      tableData: {
        url: this.apiUrl.webApi + "/safety/drivingLog/drivingLogErrorPageList",//请求地址
        method: 'post',//请求方式
        where: {},//搜索条件
        height: 'auto',//表格高度 auto
        page: true,//分页是否使用
        columns: [//表头数据
          {type: 'index', width: 70, align: 'center', title: '序号'},
          {title: '车牌号', minWidth: 110, key: 'vehiclePlateNo'},
          {title: '车辆颜色', minWidth: 110, key: 'vehiclePlateColor', render: (h, params) => {
              if (params.row.vehiclePlateColor == 1) {
                return h('Tag',{  props: { color: 'primary'}}, '蓝色');
              }else if (params.row.vehiclePlateColor == 2) {
                return h('Tag',{  props: { color: 'warning'}},  '黄色');
              }else if (params.row.vehiclePlateColor == 5) {
                return h('Tag',{  props: { color: 'success'}},  '绿色');
              }else{
                return h('Tag',{  props: {color: 'default'}},  '未获取颜色');
              }
            }
          },
          {title: '车主/业户', minWidth: 100, key: 'vehicleOwnerName', render: (h, params) => {
              return h('span',!!params.row.vehicleOwnerName ? params.row.vehicleOwnerName:'--');
            }
          },
          {title: '联系电话', minWidth: 130, key: 'vehicleOwnerPhone', render: (h, params) => {
              return h('span',!!params.row.vehicleOwnerPhone ? params.row.vehicleOwnerPhone:'--');
            }
          },
          {title: '车架号', minWidth: 180, key: 'vehicleFrameNo'},
          {title: '当日里程', minWidth: 170, key: 'mileageDay'},
          {title: '运行时长', minWidth: 170, key: 'runTime'},
          {title: '行驶时间', minWidth: 300, key: 'beginTime', render: (h, params) => {
              return h('span',params.row.beginTime + ' 至 ' +params.row.endTime);
            }
          },
          {title: '运输企业', minWidth: 260, key: 'deptName'},
        ],
        format: {//返回数据格式
          list: ['data'],//数据list
          count: ['count'],//数据总量
        },
      },
    }
  },
  mounted() {//mounted 挂载结束状态
    var that = this;


    /*加载子企业列表*/
    that.axios.post(that.apiUrl.coreDeptCoreDeptList, {}).then(res => {
      if (!!res) {
        that.subDeptList = res.data.data;
      }
    }).catch(err => {
      console.log("失败", err)
    })


  },
  methods: {//执行的方法
    searchSubmit() {//搜索
      this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
      this.$refs.wzTbale.tableLoadData(true);
    },
    //车辆导出
    vehicleExport() {
      let that = this;
      that.spinShow = true;
      that.axios.post(that.apiUrl.webApi + "/safety/drivingLog/drivingLogErrorExport",  that.formDataSearch).then(res => {
        that.spinShow = false;
        if (!!res) {
          window.open(that.apiUrl.imgUrl + res.data.data)
        }
      }).catch(err => {
        console.log('失败', err);
      })
    },
  },
  watch: {//监听

  },
  beforeUpdate() {//beforeUpdate 更新前状态

  },
  updated() {//updated 更新完成状态

  },
  beforeDestroy() {//beforeDestroy 销毁前状态

  },
  destroyed() {//destroyed 销毁完成状态

  }
}
</script>

<style lang="less">
._wz_abnormalTraffic {
  display: flex;
  flex-direction: column;


}
</style>
